﻿Imports System.Data.OleDb

Public Class BanVe
    Inherits DataProvider
    
    Public Function GetHV(ByVal macb As String) As DataSet
        Dim dtobanve As New DataSet
        Dim str As String = ""
        If Not macb = "System.Data.DataRowView" Then
            str = "SELECT * FROM ChuyenBay_HangVe WHERE ChuyenBay=" + macb
        End If
        dtobanve = Nothing
        If Not str = "" Then
            dtobanve = GetDT(str)
        End If
        Return dtobanve
    End Function

    Public Function GetCBHV(ByVal macb As String, ByVal mahv As String) As DataSet
        Dim dtobanve As New DataSet
        Dim str As String = ""
        If Not macb = "System.Data.DataRowView" And Not mahv = "System.Data.DataRowView" Then
            str = "SELECT ChuyenBay.* FROM HangVe INNER JOIN (ChuyenBay INNER JOIN ChuyenBay_HangVe ON ChuyenBay.ID " +
                "= ChuyenBay_HangVe.ChuyenBay) ON HangVe.ID = ChuyenBay_HangVe.HangVe WHERE(((ChuyenBay.ID) = " + macb +
                ") And ((HangVe.ID) = " + mahv + "))"
        End If
        dtobanve = Nothing
        If Not str = "" Then
            dtobanve = GetDT(str)
        End If
        Return dtobanve
    End Function

    Public Function GetSB() As DataSet
        Dim dtobanve As New DataSet
        Dim sqlstr As String = "SELECT * FROM SanBay"
        dtobanve = GetDT(sqlstr)
        Return dtobanve
    End Function

    Public Function GetChuyenBay(ByVal masb As Integer, ByVal masbd As Integer, ByVal dbay As String) As DataSet
        Dim dtobanve As New DataSet
        Dim sqlstr As String = "SELECT * FROM ChuyenBay WHERE SanBaydi=" + masbd.ToString() + " AND SanBayDen=" + masb.ToString() + " AND NgayBay= #" + dbay + "#"
        dtobanve = GetDT(sqlstr)
        Return dtobanve
    End Function

    Public Function GetCMND(ByVal cmnd As String) As DataSet
        Dim sqlstr As String = "SELECT * FROM HanhKhach WHERE CMND='" + cmnd + "'"
        Return GetDT(sqlstr)
    End Function
    Public Function LuuKH(ByVal khachhang As DTO.BanVe) As Integer
        Dim sqlstr As String = "INSERT INTO HanhKhach(HoTen,DienThoai,CMND) VALUES('" + khachhang.hoten + "','" + khachhang.dienthoai + "','" + khachhang.cmnd + "')"
        Return Me.SaveData(sqlstr)
    End Function

    Public Function Muave(ByVal vecb As DTO.BanVe) As Integer
        Dim sqlstr As String = "INSERT INTO MuaVe(ChuyenBay_HangVe,HanhKhach,NgayMua,GiaVe) VALUES(" + vecb.macb_hv.ToString + "," + vecb.mahanhkhach.ToString + ",'" + vecb.ngaymua.ToShortDateString + "'," + vecb.giave.ToString + ")"
        Return Me.SaveData(sqlstr)
    End Function

    Public Function GetSBTG(ByVal mcb As String) As DataSet
        Dim sql As String = "SELECT SanBay.Ten, ChuyenBay.ID FROM SanBay INNER JOIN (ChuyenBay INNER JOIN ChuyenBay_SanBayTrungGian " +
            "ON ChuyenBay.ID = ChuyenBay_SanBayTrungGian.ChuyenBay) ON SanBay.ID = ChuyenBay_SanBayTrungGian.SanBay" +
            " WHERE(((ChuyenBay.ID) = " + mcb + "))"
        Return Me.GetDT(sql)
    End Function

    Public Function LayMaCBHV(ByVal macb As Integer, ByVal mahv As Integer) As DataSet
        Dim sql As String = "SELECT * FROM ChuyenBay_HangVe WHERE ChuyenBay=" + macb.ToString + " AND HangVe=" + mahv.ToString
        Return Me.GetDT(sql)
    End Function

    Public Function DemSoGheDat(ByVal macbhv As Integer) As Integer
        Dim sql As String = "SELECT * FROM MuaVe WHERE ChuyenBay_HangVe=" + macbhv.ToString
        Dim soghe As Integer = Me.GetDT(sql).Tables(0).Rows.Count
        Dim sql1 As String = "SELECT * FROM DatVe WHERE ChuyenBay_HangVe=" + macbhv.ToString
        soghe = soghe + Me.GetDT(sql1).Tables(0).Rows.Count
        Return soghe
    End Function
End Class
